package com.itheima.methodreference;

import java.util.Arrays;

public class Demo1 {

    public static void main(String[] args) {

        //静态方法引用
        //格式：类名::方法名
        //如果这个Lambda表达式里只是调用了某个静态方法，并且"->"前后参数的形式一致，就可以使用静态方法引用
        test();

    }

    public static void test() {

        Student[] students = new Student[5];
        students[0] = new Student("张三", 18, "男", 1.81);
        students[1] = new Student("李四", 14, "女", 1.72);
        students[2] = new Student("王五", 20, "男", 1.83);
        students[3] = new Student("赵六", 22, "女", 1.74);
        students[4] = new Student("孙七", 12, "男", 1.75);

        //Arrays.sort(students, (o1, o2) -> o1.getAge() - o2.getAge());
        //Arrays.sort(students, (o1, o2) -> Student.compareByAge(o1, o2));

        //如果这个Lambda表达式里只是调用了某个静态方法，并且"->"前后参数的形式一致，就可以使用静态方法引用
        Arrays.sort(students, Student::compareByAge);

        for (Student student : students) {
            System.out.println(student);
        }
    }
}
